import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-22
 * Time: 10:54
 */
class Students implements Comparable<Students>{
    String name;
    int age;

    public Students(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Students{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Students o) {
        return this.age - o.age;
    }
}

public class Sort {
    public static void mySort(Comparable[] comparables) {
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if(comparables[j].compareTo(comparables[j+1]) > 0) {
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Students[] students = {
                new Students("dings",18),
                new Students("huahua",20),
                new Students("perper",6)
        };
        System.out.println("排序前："+ Arrays.toString(students));

        mySort(students);

        System.out.println("排序后："+ Arrays.toString(students));

    }
}
